home *** CD-ROM | disk | FTP | other *** search
- unit ntc_client_form;
- {
- Copyright (C) 2004 - 2006 Andrew Sprott
-
- http://astronomy.crysania.co.uk
- astro@trefach.co.uk
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- }
-
- interface
-
- uses
- Windows,
- Messages,
- SysUtils,
- Classes,
- Graphics,
- Controls,
- Forms,
- Dialogs,
- ShellAPI,
- StdCtrls,
- Buttons,
- inifiles,
- ComCtrls,
- Menus,
- ExtCtrls,
- Mask,
- ScktComp,
-
- ntc_client_button;
-
- const
- { network }
- socket_number=8383;
- { messages }
- no_response='No response from server';
- lost_connection='lost connection with server';
- stop_error='NTC failed to stop the scope, '+
- 'it could be that there is a error '+
- 'or the network connection has failed';
- { events }
- event_0=0;
- { scope types }
- no_scope=0;
- lx200_type=1;
- autostar_type=2;
- { interface }
- button_width=57;
- max_menu_items=10;
-
- type
- p_dimensions_record=^dimensions_record;
- dimensions_record=record
- vdu_index,
- old_vdu_index,
- screen_left,
- screen_top,
- last_screen_height,
- last_screen_width,
- current_height,
- current_width,
- form_top,
- form_left:integer;
- end;
-
- Tscope = class(TForm)
- controller_pages: TPageControl;
-
- { constructors etc }
- procedure formcreate(
- Sender:TObject);
-
- procedure kill(
- Sender:TObject;
- var CanClose:Boolean);
-
- { configuration backup }
- procedure get_dimensions(
- form:tform;
- dimensions:p_dimensions_record;
- section:string;
- ini_file:tinifile);
-
- procedure write_dimensions(
- dimensions:p_dimensions_record;
- left,
- top:integer;
- section:string;
- ini_file:tinifile);
-
- procedure load_settings;
- procedure save_settings;
-
- { events }
- procedure control_button_click(
- Sender: TObject);
-
- procedure FormShow(
- Sender: TObject);
-
- procedure find_vdu(
- form:tform;
- dimensions:p_dimensions_record);
-
- procedure form_activate(
- form:tform;
- dimensions:p_dimensions_record);
-
- procedure check_activate(
- Sender: TObject);
-
- procedure change_page;
-
- procedure page_change(
- Sender: TObject);
-
- { menu item event handlers }
- procedure sticky_handler(
- sender:tobject);
-
- procedure buttonContextPopup(
- Sender: TObject;
- MousePos: TPoint;
- var Handled: Boolean);
-
- private
- { Private declarations }
- previous_page,
- current_page:ttabsheet;
- active_page:integer;
- { menu handling }
- menu_items:array[1..max_menu_items] of TMenuItem;
- context_menu:tpopupmenu;
- im:integer;
- { menu handler parameters }
- button:tscope_button;
-
- public
- { Public declarations }
- { configuration }
- dimensions:dimensions_record;
-
- { events }
- procedure show_hide(
- sender:tobject;
- v:boolean);
-
- end;
-
- { global variables }
- var
- scope:tscope;
- application_path:string;
- scope_type:word;
- { configuration }
- ini_file:tinifile;
-
- implementation
-
- uses
- ntc_client_network,
- ntc_client_control,
- ntc_client_info,
- ntc_client_focus,
- ntc_client_tracking,
- ntc_client_about,
- ntc_client_search,
- ntc_client_sun,
- ntc_client_moon,
- ntc_client_planets,
- ntc_client_catalogs;
-
- {$R *.DFM}
-
- { ------------
- constructors
- ------------ }
-
- procedure tscope.formcreate(
- Sender:TObject);
- begin
- application_path:=extractfilepath(paramstr(0));
- scope_type:=autostar_type;
- previous_page:=nil;
- load_settings;
- controller_pages.activepage:=current_page;
- end;
-
- procedure tscope.kill(
- Sender:TObject;
- var CanClose:Boolean);
- begin
- save_settings;
- scope_network.kill;
- scope_control.free;
- scope_search.free;
- scope_network.free;
- scope_focus.free;
- scope_info.free;
- scope_tracking.free;
- scope_sun.free;
- scope_moon.free;
- scope_planets.free;
- scope_catalogs.free;
- scope_about.free;
- canclose:=true;
- end;
-
- { --------------------
- configuration backup
- -------------------- }
-
- procedure Tscope.find_vdu(
- form:tform;
- dimensions:p_dimensions_record);
- var
- i,lw,lh:integer;
- done,vdu_changed:boolean;
-
- procedure switch_monitor;
- begin
- with dimensions^,screen.monitors[vdu_index] do
- begin
- if screen_left<0 then
- begin
- if form_left>=0 then
- form_left:=form_left+screen_left+left
- else
- form_left:=abs(form_left-screen_left)+left;
- end
- else
- form_left:=form_left-screen_left+left;
- if screen_top<0 then
- begin
- if form_top>=0 then
- form_top:=form_top+screen_top+top
- else
- form_top:=abs(form_top-screen_top)+top;
- end
- else
- form_top:=form_top-screen_top+top;
- screen_left:=left;
- screen_top:=top;
- end;
- end;
-
- begin
- with screen,dimensions^ do
- begin
- vdu_changed:=false;
- if vdu_index>=0 then
- begin
- i:=0;
- if (old_vdu_index>=0) and (old_vdu_index<monitorcount) then
- begin
- if old_vdu_index<>vdu_index then
- begin
- vdu_index:=old_vdu_index;
- switch_monitor;
- end;
- old_vdu_index:=-1;
- end;
- done:=false;
- while not done do
- if i<monitorcount then
- with monitors[i] do
- begin
- if (form_left<left) or
- (form_left>left+width) or
- (form_top<top) or
- (form_top>top+height) then
- inc(i)
- else
- begin
- if i<>vdu_index then
- vdu_index:=i;
- done:=true;
- end;
- end
- else
- begin
- done:=true;
- vdu_changed:=true;
- vdu_index:=-1;
- end;
- end;
- if vdu_index<0 then
- begin
- i:=0;
- while (i<monitorcount) and not monitors[i].Primary do
- inc(i);
- if i<monitorcount then
- vdu_index:=i
- else
- vdu_index:=0;
- vdu_changed:=true;
- end;
- with monitors[vdu_index] do
- begin
- if vdu_changed then
- switch_monitor;
- lw:=current_width;
- lh:=current_height;
- if (lw<>width) or (lh<>height) then
- begin
- current_width:=width;
- current_height:=height;
- form_left:=trunc(form_left/last_screen_width*current_width);
- if form_left+form.width>left+current_width then
- form_left:=left+current_width-form.Width;
- if form_left<left then
- form_left:=left;
- form_top:=trunc(form_top/last_screen_height*current_height);
- if form_top+form.height>top+current_height then
- form_top:=top+current_height-form.height;
- if form_top<top then
- form_top:=top;
- last_screen_width:=current_width;
- last_screen_height:=current_height;
- end
- else
- begin
- current_width:=width;
- current_height:=height;
- end;
- end;
- end;
- end;
-
- procedure tscope.get_dimensions(
- form:tform;
- dimensions:p_dimensions_record;
- section:string;
- ini_file:tinifile);
- begin
- with ini_file,dimensions^ do
- begin
- vdu_index:=readinteger(section,'monitor',-1);
- old_vdu_index:=readinteger(section,'another_monitor',-1);
- form_top:=readinteger(section,'top',form_top);
- form_left:=readinteger(section,'left',form_left);
- screen_left:=readinteger(section,'screen_left',0);
- screen_top:=readinteger(section,'screen_top',0);
- last_screen_width:=readinteger(section,'screen_width',-1);
- current_width:=last_screen_width;
- last_screen_height:=readinteger(section,'screen_height',-1);
- current_height:=last_screen_height;
- find_vdu(form,dimensions);
- end;
- end;
-
- procedure tscope.write_dimensions(
- dimensions:p_dimensions_record;
- left,
- top:integer;
- section:string;
- ini_file:tinifile);
- var
- i:integer;
- begin
- with ini_file,screen,dimensions^ do
- begin
- for i:=0 to monitorcount-1 do
- if monitors[i].primary and (vdu_index<>i) then
- old_vdu_index:=vdu_index;
- writeinteger(section,'another_monitor',old_vdu_index);
- writeinteger(section,'monitor',vdu_index);
- writeinteger(section,'left',left);
- writeinteger(section,'top',top);
- writeinteger(section,'screen_width',current_width);
- writeinteger(section,'screen_height',current_height);
- writeinteger(section,'screen_left',monitors[vdu_index].left);
- writeinteger(section,'screen_top',monitors[vdu_index].top);
- end;
- end;
-
- procedure tscope.load_settings;
- var
- l,m,ip,ib,t:integer;
- p,b,bn:string;
- pd,bd,h,s:boolean;
- ts:ttabsheet;
-
- procedure add_control_page(
- page_name:string);
- begin
- with controller_pages do
- begin
- ts:=ttabsheet.create(self);
- with ts do
- begin
- pagecontrol:=controller_pages;
- caption:=page_name;
- l:=0;
- end;
- end;
- end;
-
- procedure add_button(
- scope_control_object:scope_button_type;
- button_name:string;
- hidden,
- stuck:boolean);
- begin
- with ts,tscope_button.create(ts) do
- begin
- visible:=false;
- caption:=button_name;
- left:=l;
- width:=button_width;
- inc(l,button_width);
- if l>m then
- m:=l;
- top:=0;
- height:=25;
- parent:=ts;
- button_hidden:=hidden;
- if button_hidden then
- button_stuck:=false
- else
- begin
- button_stuck:=stuck;
- if stuck then
- font.style:=[fsbold]
- else
- font.style:=[];
- end;
- control_type:=scope_control_object;
- onclick:=control_button_click;
- oncontextpopup:=buttonContextPopup;
- visible:=true;
- end;
- end;
-
- procedure add_menu(
- i:integer;
- s:string;
- h:tnotifyevent);
- begin
- if im>max_menu_items then
- scope_network.write_status_log_check('too many menus : '+inttostr(im))
- else
- begin
- menu_items[im]:=nil;
- menu_items[im]:=tmenuitem.create(self);
- with menu_items[im] do
- begin
- caption:=s;
- checked:=false;
- onclick:=h;
- end;
- context_menu.items.add(menu_items[im]);
- end;
- inc(im);
- end;
-
- begin
- ini_file:=tinifile.create(application_path+'client.ini');
- scope_type:=ini_file.ReadInteger('main','scope_type',autostar_type);
- { menus }
- context_menu:=tpopupmenu.create(self);
- im:=1;
- add_menu(im,'Sticky Control',sticky_handler);
- { control panel }
- m:=0;
- current_page:=nil;
- with controller_pages,ini_file do
- if readinteger('main','num_control_panels',0)>0 then
- begin
- active_page:=readinteger('main','active_page',0);
- ip:=1;
- pd:=false;
- while not pd do
- begin
- p:=readstring('main','panel_'+inttostr(ip),'');
- if p<>'' then
- begin
- add_control_page(p);
- if active_page=ip then
- current_page:=ts;
- p:='panel_'+inttostr(ip);
- ib:=1;
- bd:=false;
- while not bd do
- begin
- b:='button_'+inttostr(ib)+'_';
- bn:=readstring(p,b+'name','');
- if bn<>'' then
- begin
- t:=readinteger(p,b+'module',0);
- h:=readbool(p,b+'hidden',true);
- s:=readbool(p,b+'stuck',false);
- if t>0 then
- begin
- case t of
- s_info:add_button(s_info,bn,h,s);
- s_focus:add_button(s_focus,bn,h,s);
- s_about:add_button(s_about,bn,h,s);
- s_object:add_button(s_object,bn,h,s);
- s_search:add_button(s_search,bn,h,s);
- s_control:add_button(s_control,bn,h,s);
- s_network:add_button(s_network,bn,h,s);
- s_tracking:add_button(s_tracking,bn,h,s);
- s_sun:add_button(s_sun,bn,h,s);
- s_moon:add_button(s_moon,bn,h,s);
- s_planets:add_button(s_planets,bn,h,s);
- s_catalogs:add_button(s_catalogs,bn,h,s);
- end;
- end;
- end
- else
- bd:=true;
- inc(ib);
- end;
- end
- else
- pd:=true;
- inc(ip);
- end;
- if current_page=nil then
- begin
- current_page:=controller_pages.activepage;
- active_page:=controller_pages.ActivePageIndex+1;
- end
- else
- controller_pages.activepage:=current_page;
- end
- else
- begin
- add_control_page('Setup');
- add_button(s_about,'About',true,false);
- add_button(s_network,'Network',true,false);
- add_control_page('Control');
- add_button(s_info,'Info',true,false);
- add_button(s_focus,'Focus',true,false);
- add_button(s_search,'Search',true,false);
- add_button(s_control,'Control',true,false);
- add_button(s_tracking,'Track',true,false);
- current_page:=controller_pages.ActivePage;
- active_page:=controller_pages.ActivePageIndex+1;
- add_control_page('Objects');
- add_button(s_sun,'Sun',true,false);
- add_button(s_moon,'Moon',true,false);
- add_button(s_planets,'Planets',true,false);
- add_button(s_catalogs,'Catalogs',true,false);
- end;
- scope.clientwidth:=m;
- { form }
- get_dimensions(scope,@dimensions,'main',ini_file);
- ini_file.Free;
- end;
-
- procedure tscope.save_settings;
- var
- i,j:integer;
- ps,bs:string;
- begin
- ini_file:=tinifile.create(application_path+'client.ini');
- scope_network.save_settings;
- scope_control.save_settings;
- scope_focus.save_settings;
- scope_info.save_settings;
- scope_tracking.save_settings;
- scope_search.save_settings;
- scope_sun.save_settings;
- scope_moon.save_settings;
- scope_planets.save_settings;
- scope_catalogs.save_settings;
- scope_about.save_settings;
- with ini_file do
- begin
- { control panel }
- with controller_pages do
- begin
- for i:=0 to pagecount-1 do
- begin
- ps:='panel_'+inttostr(i+1);
- writestring('main',ps,pages[i].caption);
- for j:=0 to pages[i].ControlCount-1 do
- with pages[i],tscope_button(Controls[j]) do
- begin
- bs:='button_'+inttostr(j+1)+'_';
- WriteString(ps,bs+'name',caption);
- writestring(ps,bs+'module',inttostr(control_type));
- writebool(ps,bs+'hidden',button_hidden);
- writebool(ps,bs+'stuck',button_stuck);
- end;
- end;
- writestring('main','num_control_panels',inttostr(pagecount));
- end;
- writeinteger('main','active_page',active_page);
- { form }
- find_vdu(scope,@dimensions);
- write_dimensions(@dimensions,left,top,'main',ini_file);
- end;
- ini_file.free;
- end;
-
- { ------
- events
- ------ }
-
- procedure Tscope.FormShow(
- Sender: TObject);
- begin
- with dimensions do
- begin
- top:=form_top;
- left:=form_left;
- end;
- change_page;
- end;
-
- procedure Tscope.form_activate(
- form:tform;
- dimensions:p_dimensions_record);
- var
- w,h:integer;
- begin
- with form,dimensions^ do
- begin
- find_vdu(form,dimensions);
- w:=screen.monitors[vdu_index].width;
- h:=screen.monitors[vdu_index].Height;
- if (w<>current_width) or
- (h<>current_height) then
- begin
- last_screen_width:=current_width;
- last_screen_height:=current_height;
- current_width:=w;
- current_height:=h;
- scope_network.adjust;
- scope_control.adjust;
- scope_about.adjust;
- scope_focus.adjust;
- scope_info.adjust;
- scope_sun.adjust;
- scope_moon.adjust;
- scope_planets.adjust;
- scope_catalogs.adjust;
- form_top:=trunc(form_top/last_screen_height*current_height);
- form_left:=trunc(form_left/last_screen_width*current_width);
- top:=form_top;
- left:=form_left;
- scope.show;
- end;
- end;
- end;
-
- procedure Tscope.check_activate(
- Sender: TObject);
- begin
- form_activate(scope,@dimensions);
- end;
-
- procedure Tscope.show_hide(
- sender:tobject;
- v:boolean);
- begin
- with tscope_button(sender) do
- if not v then
- begin
- if button_stuck then
- font.style:=[];
- button_stuck:=false;
- button_hidden:=true;
- end
- else
- button_hidden:=false;
- end;
-
- procedure Tscope.control_button_click(
- Sender: TObject);
- begin
- with tscope_button(sender) do
- begin
- case control_type of
- s_info:scope_info.check_visible_and_show_hide(sender);
- s_focus:scope_focus.check_visible_and_show_hide(sender);
- s_about:scope_about.check_visible_and_show_hide(sender);
- s_network:scope_network.check_visible_and_show_hide(sender);
- s_search:scope_search.check_visible_and_show_hide(sender);
- s_control:scope_control.check_visible_and_show_hide(sender);
- s_tracking:scope_tracking.check_visible_and_show_hide(sender);
- s_sun:scope_sun.check_visible_and_show_hide(sender);
- s_moon:scope_moon.check_visible_and_show_hide(sender);
- s_planets:scope_planets.check_visible_and_show_hide(sender);
- s_catalogs:scope_catalogs.check_visible_and_show_hide(sender);
- end;
- end;
- end;
-
- procedure tscope.change_page;
- var
- i:integer;
- begin
- previous_page:=current_page;
- if previous_page<>nil then
- with previous_page do
- for i:=0 to controlcount-1 do
- with tscope_button(controls[i]) do
- begin
- if not button_stuck then
- case control_type of
- s_info:scope_info.hide_form;
- s_about:scope_about.hide_form;
- s_focus:scope_focus.hide_form;
- s_network:scope_network.hide_form;
- s_search:scope_search.hide_form;
- s_control:scope_control.hide_form;
- s_tracking:scope_tracking.hide_form;
- s_sun:scope_sun.hide_form;
- s_moon:scope_moon.hide_form;
- s_planets:scope_planets.hide_form;
- s_catalogs:scope_catalogs.hide_form;
- end;
- end;
- current_page:=controller_pages.ActivePage;
- with current_page do
- for i:=0 to controlcount-1 do
- with tscope_button(controls[i]) do
- begin
- if not button_hidden then
- case control_type of
- s_info:scope_info.show_form;
- s_about:scope_about.show_form;
- s_focus:scope_focus.show_form;
- s_network:scope_network.show_form;
- s_search:scope_search.show_form;
- s_control:scope_control.show_form;
- s_tracking:scope_tracking.show_form;
- s_sun:scope_sun.show_form;
- s_moon:scope_moon.show_form;
- s_planets:scope_planets.show_form;
- s_catalogs:scope_catalogs.show_form;
- end;
- end;
- active_page:=controller_pages.ActivePageIndex+1;
- end;
-
- procedure Tscope.page_change(
- Sender: TObject);
- begin
- change_page;
- end;
-
- { -------------------
- menu event handlers
- ------------------- }
-
- { menu handlers }
- procedure tscope.sticky_handler(
- sender:tobject);
- begin
- with tmenuitem(sender) do
- begin
- with button do
- begin
- button_stuck:=not button_stuck;
- if button_stuck then
- font.Style:=[fsbold]
- else
- font.style:=[];
- end;
- end;
- end;
-
- procedure tscope.buttonContextPopup(
- Sender: TObject;
- MousePos: TPoint;
- var Handled: Boolean);
- begin
- { setup up parameters }
- button:=sender as tscope_button;
- { call popup menu }
- handled:=true;
- with button do
- context_menu.popup(
- scope.left+current_page.left+parent.left+left+mousepos.x,
- scope.top+current_page.top+parent.top+top+mousepos.y);
- end;
-
- end.
-